﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KnowledgeAssistant
{
    public partial class EditSubject : Form
    {
        public enum ActionType { add, edit}

        private ActionType action_type;
        private Subject subject;

        public EditSubject(ActionType action_type)
        {
            InitializeComponent();
            this.action_type = action_type;
            InitControlNames();
        }

        public EditSubject(Subject subject, ActionType action_type)
        {
            InitializeComponent();
            this.action_type = action_type;
            this.subject = subject;
            this.subjectname.Text = this.subject.Name;
            InitControlNames();
        }

        private void InitControlNames()
        {
            if (this.action_type == ActionType.add)
            {
                this.Text = "Добавить новый предмет";
                this.button1.Text = "Добавить";
            }
            else if (this.action_type == ActionType.edit)
            {
                this.Text = "Изменить название предмета";
                this.button1.Text = "Применить";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string subject_name = this.subjectname.Text.Trim();
            if (this.action_type == ActionType.add)
            {               
                SubjectUtil.AddSubject(subject_name);
            }
            else if (this.action_type == ActionType.edit)
            {
                SubjectUtil.EditSubject(this.subject.SubjectID, subject_name);
            }
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
